/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package projorientado.application;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

/**
 *
 * @author João Neto
 */
@Entity
@Table(name = "acessos")
@NamedQueries({@NamedQuery(name = "Acessos.findAll", query = "SELECT a FROM Acessos a"), @NamedQuery(name = "Acessos.findById", query = "SELECT a FROM Acessos a WHERE a.id = :id"), @NamedQuery(name = "Acessos.findByPlaca", query = "SELECT a FROM Acessos a WHERE a.placa = :placa"), @NamedQuery(name = "Acessos.findByDataAcesso", query = "SELECT a FROM Acessos a WHERE a.dataAcesso = :dataAcesso"), @NamedQuery(name = "Acessos.findByDuracao", query = "SELECT a FROM Acessos a WHERE a.duracao = :duracao"), @NamedQuery(name = "Acessos.findByValido", query = "SELECT a FROM Acessos a WHERE a.valido = :valido")})
public class Acessos implements Serializable {
    @Transient
    private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Basic(optional = false)
    @Column(name = "id")
    private Integer id;
    @Basic(optional = false)
    @Column(name = "placa")
    private String placa;
    @Basic(optional = false)
    @Column(name = "data_acesso")
    @Temporal(TemporalType.TIMESTAMP)
    private Date dataAcesso;
    @Basic(optional = false)
    @Column(name = "duracao")
    private int duracao;
    @Basic(optional = false)
    @Column(name = "valido")
    private boolean valido;
    @JoinColumn(name = "usuario", referencedColumnName = "id")
    @ManyToOne
    private Usuarios usuario;

    public Acessos() {
    }

    public Acessos(Integer id) {
        this.id = id;
    }

    public Acessos(Integer id, String placa, Date dataAcesso, int duracao, boolean valido) {
        this.id = id;
        this.placa = placa;
        this.dataAcesso = dataAcesso;
        this.duracao = duracao;
        this.valido = valido;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        Integer oldId = this.id;
        this.id = id;
        changeSupport.firePropertyChange("id", oldId, id);
    }

    public String getPlaca() {
        return placa;
    }

    public void setPlaca(String placa) {
        String oldPlaca = this.placa;
        this.placa = placa;
        changeSupport.firePropertyChange("placa", oldPlaca, placa);
    }

    public Date getDataAcesso() {
        return dataAcesso;
    }

    public void setDataAcesso(Date dataAcesso) {
        Date oldDataAcesso = this.dataAcesso;
        this.dataAcesso = dataAcesso;
        changeSupport.firePropertyChange("dataAcesso", oldDataAcesso, dataAcesso);
    }

    public int getDuracao() {
        return duracao;
    }

    public void setDuracao(int duracao) {
        int oldDuracao = this.duracao;
        this.duracao = duracao;
        changeSupport.firePropertyChange("duracao", oldDuracao, duracao);
    }

    public boolean getValido() {
        return valido;
    }

    public void setValido(boolean valido) {
        boolean oldValido = this.valido;
        this.valido = valido;
        changeSupport.firePropertyChange("valido", oldValido, valido);
    }

    public Usuarios getUsuario() {
        return usuario;
    }

    public void setUsuario(Usuarios usuario) {
        Usuarios oldUsuario = this.usuario;
        this.usuario = usuario;
        changeSupport.firePropertyChange("usuario", oldUsuario, usuario);
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Acessos)) {
            return false;
        }
        Acessos other = (Acessos) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "dectordeplaca.Acessos[id=" + id + "]";
    }

    public void addPropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.removePropertyChangeListener(listener);
    }

}
